﻿<UserControl
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:charting="clr-namespace:Microsoft.Windows.Controls.DataVisualization.Charting;assembly=Microsoft.Windows.Controls.DataVisualization"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:datavis="clr-namespace:Microsoft.Windows.Controls.DataVisualization;assembly=Microsoft.Windows.Controls.DataVisualization"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    x:Class="StockTraderRI.Modules.Market.TrendLine.TrendLineView"
    mc:Ignorable="d" BorderThickness="0,0,0,0"
    Height="190">
    <UserControl.Resources>
        <!-- By convention every view inside the ResearchControl (ResearchRegion) has to declare 
             a DataTemplate with the "HeaderIcon" key which defines the icon on the Header -->
        <DataTemplate x:Key="HeaderIcon">
            <Grid Margin="15,5,0,0" HorizontalAlignment="Left"  VerticalAlignment="Top" Height="13" Width="16">
                <Path Fill="{x:Null}" Stretch="Fill" Stroke="#FFFFFFFF" StrokeThickness="2" Data="M403.16667,431.66667 L403.16667,448.33299 417.00699,448.33299 417.00699,432.24967"/>
                <Path HorizontalAlignment="Left" Margin="4.503,6,0,0" Width="2" Fill="{x:Null}" Stretch="Fill" Stroke="#FFFFFFFF" StrokeThickness="2" Data="M403.16667,431.66667 L403.16667,448.33299"/>
                <Path HorizontalAlignment="Right" Margin="0,2,4.751,0" Width="2" Fill="{x:Null}" Stretch="Fill" Stroke="#FFFFFFFF" StrokeThickness="2" Data="M403.16667,431.66667 L403.16667,448.33299"/>
            </Grid>
        </DataTemplate>


        <!--LineDataPoint-->
        <ControlTemplate x:Key="LineDataPointTemplate" TargetType="charting:LineDataPoint">
            <Grid x:Name="Root" Opacity="1" RenderTransformOrigin="0.5,0.5">
                <ToolTipService.ToolTip>
                    <ContentControl Content="{TemplateBinding FormattedDependentValue}"/>
                </ToolTipService.ToolTip>
                <Ellipse Height="6" Width="6" Stroke="#FF4C89D4" Fill="#FFDDDDDD"  StrokeThickness="2"/>
            </Grid>
        </ControlTemplate>

        <!--Legend-->
        <Style x:Key="LegendStyle1" TargetType="datavis:Legend">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="datavis:Legend" />
                </Setter.Value>
            </Setter>
        </Style>
        <!--Chart Style-->
        <Style x:Key="ChartStyle1" TargetType="charting:Chart">
            <Setter Property="BorderBrush" Value="Black"/>
            <Setter Property="BorderThickness" Value="1"/>
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="StylePalette">
                <Setter.Value>
                    <datavis:StylePalette>
                        <Style TargetType="charting:LineDataPoint">
                            <Setter Property="Template" Value="{StaticResource LineDataPointTemplate}"/>
                            <Setter Property="Background">
                                <Setter.Value>
                                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                                        <GradientStop Color="#FF4C89D4"/>
                                        <GradientStop Color="#FF3A5F8E" Offset="1"/>
                                    </LinearGradientBrush>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </datavis:StylePalette>
                </Setter.Value>
            </Setter>
            <Setter Property="TitleStyle">
                <Setter.Value>
                    <Style TargetType="datavis:Title">
                        <Setter Property="Visibility" Value="Collapsed"/>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="LegendStyle">
                <Setter.Value>
                    <Style TargetType="datavis:Legend">
                        <Setter Property="Margin" Value="15,0,15,0"/>
                        <Setter Property="VerticalAlignment" Value="Center"/>
                        <Setter Property="BorderBrush" Value="#FFDBDBDB"/>

                        <Setter Property="Background">
                            <Setter.Value>
                                <LinearGradientBrush EndPoint="0.442,0.005" StartPoint="0.558,0.995">
                                    <GradientStop Color="#FFDBDBDB"/>
                                    <GradientStop Color="#FFFFFFFF" Offset="1"/>
                                </LinearGradientBrush>
                            </Setter.Value>
                        </Setter>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="ChartAreaStyle">
                <Setter.Value>
                    <Style TargetType="Grid">
                        <Setter Property="MinWidth" Value="100"/>
                        <Setter Property="MinHeight" Value="75"/>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="PlotAreaStyle">
                <Setter.Value>
                    <Style TargetType="Grid">
                        <Setter Property="Background" Value="{x:Null}" />
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="charting:Chart">
                        <Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Padding="10">
                            <Grid UseLayoutRounding="False">
                                <Grid.RowDefinitions>
                                    <RowDefinition Height="Auto"/>
                                    <RowDefinition Height="*"/>
                                </Grid.RowDefinitions>
                                <datavis:Title Style="{TemplateBinding TitleStyle}" Content="{TemplateBinding Title}" Foreground="#FFFFFFFF"/>
                                <Grid Margin="0,15,0,15" Grid.Row="1" UseLayoutRounding="False">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="*"/>
                                        <ColumnDefinition Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <datavis:Legend x:Name="Legend" Style="{StaticResource LegendStyle1}" Grid.Column="1" Title="{TemplateBinding LegendTitle}" Background="{x:Null}" VerticalAlignment="Center"/>
                                    <Grid x:Name="ChartArea" Style="{TemplateBinding ChartAreaStyle}" UseLayoutRounding="False">
                                        <Grid x:Name="PlotArea" Style="{TemplateBinding PlotAreaStyle}" UseLayoutRounding="True">
                                            <Grid x:Name="GridLinesContainer"/>
                                            <Grid x:Name="SeriesContainer" UseLayoutRounding="True"/>
                                        </Grid>
                                    </Grid>
                                </Grid>
                            </Grid>
                        </Border>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        
        <!--Legend Item Style-->
        <Style x:Key="LegendItemStyle1" TargetType="charting:LegendItem">
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="charting:LegendItem">
                        <StackPanel Orientation="Horizontal">
                            <Rectangle Height="8" Margin="0,0,3,0" Width="8" Fill="{Binding Path=Background}" Stroke="{Binding Path=BorderBrush}" StrokeThickness="1"/>
                            <datavis:Title Content="{TemplateBinding Content}" Foreground="White"/>
                        </StackPanel>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        
        <!--Line Series Style-->
        <Style x:Key="LineSeriesStyle1" TargetType="charting:LineSeries">
            <Setter Property="IsTabStop" Value="False"/>
            <Setter Property="MarkerWidth" Value="20"/>
            <Setter Property="MarkerHeight" Value="20"/>
            <Setter Property="PolylineStyle">
                <Setter.Value>
                    <Style TargetType="Polyline">
                        <Setter Property="StrokeThickness" Value="2"/>
                    </Style>
                </Setter.Value>
            </Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="charting:LineSeries">
                        <Canvas x:Name="PlotArea">
                            <Polyline Style="{TemplateBinding PolylineStyle}" Stroke="{TemplateBinding Background}" Points="{TemplateBinding Points}" />
                        </Canvas>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

    </UserControl.Resources>
	<Border BorderThickness="0,0,0,1" BorderBrush="#FFFFFFFF" Padding="10,10,10,10">
        <Grid x:Name="MainGrid">
            <Grid.RowDefinitions>
				<RowDefinition Height="Auto"/>
				<RowDefinition Height="Auto"/>
			</Grid.RowDefinitions>
            <StackPanel Orientation="Horizontal" Margin="0,0,0,0">
                <TextBlock Text="{Binding TickerSymbol}" Style="{StaticResource TextBlockSectionTitle}" />
                <TextBlock Text=" HISTORICAL DATA" Style="{StaticResource TextBlockSectionTitle}" AutomationProperties.AutomationId="HistoricalDataTextBlock" />
            </StackPanel>
            <Border Grid.Row="1">
			    <charting:Chart Grid.Row="1" Style="{StaticResource ChartStyle1}" x:Name="lineChart" Title="{Binding Path=TickerSymbol}" Height="170" BorderThickness="0" FontFamily="Arial" FontSize="10" Foreground="#FF313131">
                    <charting:Chart.Axes>
                        <charting:LinearAxis ShowGridLines="True" BorderThickness="1" MaxHeight="85" />
                        <charting:DateTimeAxis Orientation="Horizontal" ShowGridLines="False" IntervalType="Days" MaxWidth="150" BorderThickness="1" />
                    </charting:Chart.Axes>

                    <charting:Chart.Series>
					    <charting:LineSeries
                            Style="{StaticResource LineSeriesStyle1}"   LegendItemStyle="{StaticResource LegendItemStyle1}" 
						    ItemsSource="{Binding Path=HistoryCollection}"
						    DependentValueBinding="{Binding Path=Value}"
						    IndependentValueBinding="{Binding Path=DateTimeMarker}" />
				    </charting:Chart.Series>
			    </charting:Chart>
            </Border>
		</Grid>
	</Border>
</UserControl>
